﻿@using Inovout.Data.Domain
@model System.Collections.IEnumerable

<table class="table table-hover table-striped table-bordered">
    <thead>
        <tr>
            @using (var elementHtml = Html.GetElementHtmlHelper())
            {
                foreach (var property in elementHtml.ViewData.ModelMetadata.Properties)
                {
                <th class="col-md-@property.AsWidgetModelMetadata().GridColumnCount">
                    @elementHtml.DisplayName(property.PropertyName)
                    @if (Model is IDataObjectPagedSet && Html.ViewData.GetOrderCriterias(Model).Any(o => o.OrderName.Equals(property.PropertyName)))
                    {
                        if (Html.ViewData.GetOrderCriterias(Model).Single(o => o.OrderName.Equals(property.PropertyName)).OrderAscending)
                        {
                        <span>@Html.ActionLink("降序", Html.ViewContext.RouteData.GetRequiredString("action"),
                        QueryCriteriaHelper.BuildRouteDictionary(Html.ViewData.GetQueryCriteria(Model),
                       new RouteValueDictionary { { "ps", ((IDataObjectPagedSet)Model).PageSize }, { "pi", ((IDataObjectPagedSet)Model).PageIndex } }
                        , property.PropertyName, true))
                        </span>
                        }
                        else
                        {
                        <span>@Html.ActionLink("升序", Html.ViewContext.RouteData.GetRequiredString("action"),
                        QueryCriteriaHelper.BuildRouteDictionary(Html.ViewData.GetQueryCriteria(Model),
                       new RouteValueDictionary { { "ps", ((IDataObjectPagedSet)Model).PageSize }, { "pi", ((IDataObjectPagedSet)Model).PageIndex } }
                        , property.PropertyName, true))
                        </span>
                        }
                    }
                </th>
                }
            }
        </tr>
    </thead>
    <tbody>
        @if (Model != null && Model.GetEnumerator().MoveNext())
        {
            foreach (var element in Model)
            {
            <tr>
                @using (var elementHtml = Html.GetElementHtmlHelper(element))
                {
                    foreach (var property in elementHtml.ViewData.ModelMetadata.Properties)
                    {
                    <td>@elementHtml.Display(property.PropertyName)</td>
                    }
                }
            </tr>
            }
        }
        else
        {
            <tr>
                <td colspan="@Html.ViewData.ModelMetadata.AsWidgetCollectionModelMetadata().WidgetElementModelMetadata.Properties.Count()">
                    @Html.Raw(Html.ViewData.ModelMetadata.NullDisplayText)
                </td>
            </tr>
        }
    </tbody>
</table>
@if (Model is IDataObjectPagedSet)
{
    @Html.Partial("_Pager", Model, Html.ViewData)
}